const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

let entry = require('./webpack.common.js')();

module.exports = {
    entry,
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['env'],
                        plugins: ['transform-runtime']
                    }
                }
            }
        ]
    },
    resolve: {
        extensions: ['.js'],
        alias: {
            '@': path.join( __dirname, '/src/resource/js/')
        }
    },
    plugins: [
        new CleanWebpackPlugin(['./src/static/js']),
        new webpack.optimize.CommonsChunkPlugin({
            name: 'js/vendor',
            children: true,
            async: true
        }),
        new UglifyJSPlugin({
            sourceMap: true,
            warningsFilter: (src) => true
        }),
        new webpack.SourceMapDevToolPlugin({
            filename: 'js/[name].js.map',
            exclude: ['js/vendor.js']
        })
    ],
    output: {
        path: path.resolve( __dirname, 'src/static'),
        filename: 'js/[name].js',
        chunkFilename: 'js/[name].js'
    }
};